/**
 * 
 */
package co.fitstart.payment.entity.transaction;

import java.util.Date;

import co.fitstart.payment.entity.request.RequestRecord;

/**
 * @author lute
 * 
 * 交易记录
 */
public class TransactionRecord {

    private Long id;
    
    private Long appId;
    
    private Long channelId;
    
    /** 交易总额 分为单位 */
    private int amount;
    
    /** 订单号 */
    private String orderNo;
    
    /** 支付请求号 */
    private String requestNo;
    
    /** 支付机构方交易号 */
    private String tradeNo;
    
    /** 银行卡号 */
    private String cardNo;
    
    /** 交易状态 */
    private int transactionStatusAsInt;
    
    /** 交易状态最近更改时间 */
    private Date lastModifiedTime;
    
    /**
     * The default constructor
     */
    public TransactionRecord(){
        
    }
    
    /**
     * @param requestRecord
     * @param tradeNo
     * @param amount
     */
    public TransactionRecord(RequestRecord requestRecord, String tradeNo, int amount) {
        this.appId = requestRecord.getAppId();
        this.channelId = requestRecord.getChannelId();
        this.amount = amount;
        this.orderNo = requestRecord.getOrderNo();
        this.requestNo = requestRecord.getRequestNo();
        this.tradeNo = tradeNo;
        this.transactionStatusAsInt = TransactionStatus.CREATED.getCode();
        this.lastModifiedTime = new Date();
    }
    
    /**
     * Get transaction status
     * 
     * @return
     */
    public TransactionStatus getTransactionStatus() {
        return TransactionStatus.codeOf(this.transactionStatusAsInt);
    }
    
    /**
     * Change trade number
     * 
     * @param tradeNo
     * @return
     */
    public TransactionRecord tradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
        this.lastModifiedTime = new Date();
        return this;
    }
    
    /**
     * Change transaction status
     * 
     * @param transactionStatus
     * @return
     */
    public TransactionRecord transactionStatus(TransactionStatus transactionStatus) {
        this.transactionStatusAsInt = transactionStatus.getCode();
        this.lastModifiedTime = new Date();
        return this;
    }
    
    /**
     * Change last modified time
     * 
     * @param lastModifiedTime
     * @return
     */
    public TransactionRecord lasModifiedTime(Date lastModifiedTime) {
        this.lastModifiedTime = lastModifiedTime;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the appId
     */
    public Long getAppId() {
        return appId;
    }

    /**
     * @return the channelId
     */
    public Long getChannelId() {
        return channelId;
    }

    /**
     * @return the amount
     */
    public int getAmount() {
        return amount;
    }

    /**
     * @return the orderNo
     */
    public String getOrderNo() {
        return orderNo;
    }

    /**
     * @return the requestNo
     */
    public String getRequestNo() {
        return requestNo;
    }

    /**
     * @return the tradeNo
     */
    public String getTradeNo() {
        return tradeNo;
    }

    /**
     * @return the cardNo
     */
    public String getCardNo() {
        return cardNo;
    }

    /**
     * @return the transactionStatusAsInt
     */
    public int getTransactionStatusAsInt() {
        return transactionStatusAsInt;
    }

    /**
     * @return the lastModifiedTime
     */
    public Date getLastModifiedTime() {
        return lastModifiedTime;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param appId the appId to set
     */
    public void setAppId(Long appId) {
        this.appId = appId;
    }

    /**
     * @param channelId the channelId to set
     */
    public void setChannelId(Long channelId) {
        this.channelId = channelId;
    }

    /**
     * @param amount the amount to set
     */
    public void setAmount(int amount) {
        this.amount = amount;
    }

    /**
     * @param orderNo the orderNo to set
     */
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    /**
     * @param requestNo the requestNo to set
     */
    public void setRequestNo(String requestNo) {
        this.requestNo = requestNo;
    }

    /**
     * @param tradeNo the tradeNo to set
     */
    public void setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
    }

    /**
     * @param cardNo the cardNo to set
     */
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    /**
     * @param transactionStatusAsInt the transactionStatusAsInt to set
     */
    public void setTransactionStatusAsInt(int transactionStatusAsInt) {
        this.transactionStatusAsInt = transactionStatusAsInt;
    }

    /**
     * @param lastModifiedTime the lastModifiedTime to set
     */
    public void setLastModifiedTime(Date lastModifiedTime) {
        this.lastModifiedTime = lastModifiedTime;
    }

}
